package com.itheima.day14.threadpool.test1;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

// 默认线程池对象的创建与简单使用
public class Test {
    public static void main(String[] args) throws InterruptedException {
        // 创建一个默认的线程池对象，池子默认是空的，默认最多可以容纳int类型的最大值
        ExecutorService executorService = Executors.newCachedThreadPool();
        // Executors        可以帮助我们创建线程池对象
        // ExecutorService  可以帮助我们控制线程池

        // method1(executorService);

        executorService.submit(() -> {
            System.out.println(Thread.currentThread().getName() + "正在执行");
        });

        // 让main线程睡眠1000毫秒
        Thread.sleep(1000);

        executorService.submit(() -> {
            System.out.println(Thread.currentThread().getName() + "正在执行");
        });

    }

    private static void method1(ExecutorService executorService) {
        executorService.submit(new Runnable() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName() + "正在执行");
            }
        });

        executorService.submit(() -> {
            System.out.println(Thread.currentThread().getName() + "正在执行");
        });
    }
}
